package com.tju.welding.controller;

import javax.servlet.http.HttpSession;

import com.tju.welding.service.ProjectService;
import com.tju.welding.utils.ApiResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProjectController {

    @Autowired
    ProjectService projectService;

    @PostMapping("/api/project")
    ApiResponse createProject(@RequestParam("projectName") String projectName, HttpSession session) {
        return projectService.createProject(projectName, session);
    }

    @PostMapping("api/project/member")
    ApiResponse addProjectMember(@RequestParam("projectId") int projectId, @RequestParam("userId") int userId,
            @RequestParam("memberType") int memberType, HttpSession session) {
        return projectService.addProjectMember(projectId, userId, memberType, session);
    }

    @PostMapping("/api/project/port/job")
    ApiResponse assignJob(@RequestParam("portId") int portId, @RequestParam("welderId") int welderId, HttpSession session){
        return projectService.assignJob(portId, welderId, session);
    }

    @DeleteMapping("/api/project/member")
    ApiResponse deleteProjectMember(@RequestParam("projectId") int projectId, @RequestParam("userId") int userId,
            HttpSession session) {
        return projectService.deleteProjectMember(projectId, userId, session);
    }

    @PutMapping("/api/project/name")
    ApiResponse alterProjectName(@RequestParam("projectId") int projectId, @RequestParam("newName") String newName,
            HttpSession session) {
        return projectService.alterProjectName(projectId, newName, session);
    }

    @GetMapping("/api/project/managed")
    ApiResponse getManagedProjects(HttpSession session){
        return projectService.getManagedProject(session);
    }

}
